/// <reference name="MicrosoftAjax.debug.js" />
/// <reference path="../Iframe.debug.js" />
/// <reference path="../FieldConstraints.debug.js" />

Type.registerNamespace("BM");

// BubbleTooltipAddition object

BM.BubbleTooltipAddition = function(leafItem, additionNode) {
    BM.BubbleTooltipAddition.initializeBase(this, [leafItem, additionNode]);
}

BM.BubbleTooltipAddition.prototype = {
}

BM.Addition['BubbleTooltipAddition'] = BM.BubbleTooltipAddition;
BM.BubbleTooltipAddition.registerClass("BM.BubbleTooltipAddition", BM.Addition);

BM.BubbleTooltipAddition.fix = function(fieldData) {
    if (BM.Iframe.checkIE6) {
        var iframe = BM.Iframe.getDuplication(fieldData);
        BM.Iframe.refreshProperties(fieldData, 'fieldDataIframe');
        fieldData.insertAdjacentElement('afterEnd', iframe);
        iframe.style.marginLeft = parseInt(fieldData.style.marginLeft) + "px";
        iframe.style.marginTop = parseInt(fieldData.style.marginTop) + "px";
    }
}

BM.BubbleTooltipAddition.showUnder = function(fieldData, input) {
    if (parseInt(input.offsetWidth) > 180) {
        fieldData.style.width = parseInt(input.offsetWidth) + "px";
    }
    else {
        fieldData.style.width = 180 + "px";
    }
    fieldData.style.marginLeft = -(parseInt(input.offsetWidth)) + "px";
    fieldData.style.marginTop = parseInt(input.offsetHeight) + "px";
}

BM.BubbleTooltipAddition.show = function(node) {
    var fc = BM.FieldConstraints.get();
    var fieldData = fc.createOrGetNode();
    fieldData.style.position = 'absolute';
    fieldData.style.zIndex = '1000';
    node.appendChild(fieldData);
    fieldData.style.display = 'block';
    var item = MItem.getByNode(node.parentNode);
    fc.show(item);
    var input = item.getInput();
    BM.BubbleTooltipAddition.showUnder(fieldData, input);
    BM.BubbleTooltipAddition.fix(fieldData);
}

BM.BubbleTooltipAddition.hide = function(node) {
    var fieldData = BM.FieldConstraints.getFieldData();
    if (fieldData == null) return;
    fieldData.style.display = 'none';
    BM.Iframe.hide(fieldData);
}